package bootsxt.utils;

import java.util.ArrayDeque;
import java.util.Queue;

public class AutoEvictQueue<T> {
    private final int capacity;
    private final Queue<T> queue;

    public AutoEvictQueue(int capacity) {
        this.capacity = capacity;
        this.queue = new ArrayDeque<>(capacity);
    }

    public boolean offer(T element) {
        if (queue.size() >= capacity) {
            // 如果队列满了，删除最早的元素
            queue.poll();
        }
        return queue.offer(element);
    }

    public T poll() {
        return queue.poll();
    }

    public T peek() {
        return queue.peek();
    }

    public int size() {
        return queue.size();
    }

    public boolean isEmpty() {
        return queue.isEmpty();
    }
    
    public boolean isFull() {
        return queue.size() >= capacity;
    }
}
